import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import store from './store/index'
import httpPlugins from './http/index'
import utilsPlugins from './utils'
import ElementUI from 'element-ui'
// css
import './assets/css/animate.css'
import './assets/css/common.less'
import './assets/css/ele.less'
import './assets/css/transition.less'
import './assets/css/iconfont/iconfont.css'
import 'element-ui/lib/theme-chalk/index.css'
// base css
import 'normalize.css/normalize.css'
// 进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css' // progress bar style
// 懒加载
import VueLazyload from 'vue-lazyload'
import * as filters from './filters'

NProgress.configure({ showSpinner: false }) // NProgress Configuration

Vue.prototype.$api = httpPlugins
Vue.config.productionTip = false
Vue.use(VueLazyload, {
  preLoad: 1.3,
  error: '/lazyImg/logo.png',
  loading: '/lazyImg/imgLoading.gif',
  attempt: 1
})
Vue.use(ElementUI)
Vue.use(httpPlugins)
Vue.use(utilsPlugins)

Object.keys(filters).forEach(ele => {
  Vue.filter(ele, filters[ele])
})

router.beforeEach((to, from, next) => {
  let arr = []
  if (to.path === '/home') {
    store.commit('SET_CURRENT_MENU', [])
  } else {
    arr.push({
      path: to.path,
      meta: to.meta
    })
    store.commit('SET_CURRENT_MENU', arr)
  }
  if (to.path === '/person') {
    document.title = to.meta.showTitle
  }
  NProgress.start()
  next()
})

router.afterEach((to) => {
  window.scrollTo(0, 0)
  NProgress.done()
})

// global
window.$globalHub = new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')
